Skip to content

fix(ui): fix flash between home and new chat#4143

Merged
TheodoreSpeaks merged 1 commit intostagingfrom
fix/home-task-transition-flash
Apr 14, 2026
Merged

fix(ui): fix flash between home and new chat#4143
TheodoreSpeaks merged 1 commit intostagingfrom
fix/home-task-transition-flash

Conversation

@TheodoreSpeaks
Copy link
Copy Markdown
Collaborator

Summary

Switching nextjs routes causes a brief flash. Reverted to directly modifying url instead of changing nextjs state.

Type of Change

  • Bug fix
  • New feature
  • Breaking change
  • Documentation
  • Other: ___________

Testing

  • Validated flash doesn't exist

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Screenshots/Videos

@vercel
Copy link
Copy Markdown

vercel bot commented Apr 14, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Apr 14, 2026 1:14am

Request Review

@cursor
Copy link
Copy Markdown

cursor bot commented Apr 14, 2026

PR Summary

Low Risk
Low risk UI navigation tweak: replaces Next.js route replacement with window.history.replaceState, which could affect expected router-driven state updates but does not touch data or auth logic.

Overview
Prevents a brief UI flash when a new chat session is created by stopping the Next.js router.replace transition.

When the first chat session event assigns a new chatId, the hook now updates the URL via window.history.replaceState to /workspace/${workspaceId}/task/${chatId} instead of triggering a client-side route change.

Reviewed by Cursor Bugbot for commit 5ae0b42. Bugbot is set up for automated code reviews on this repo. Configure here.

Copy link
Copy Markdown

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5ae0b42. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps bot commented Apr 14, 2026

Greptile Summary

Replaces router.replace / router.push with window.history.replaceState when assigning a new chat ID to the URL, bypassing Next.js's routing lifecycle and eliminating the visual flash between the home page and the new-chat view.

The router variable (line 712) and the useRouter import (line 4) are now unused dead code: router is only referenced in the useCallback dependency array (line 2174) but never called inside the callback body.

Confidence Score: 5/5

Safe to merge — the fix is correct and the only remaining finding is dead-code cleanup (P2).

The core change (using window.history.replaceState instead of router navigation) correctly eliminates the flash with no functional regression. The only open finding is an unused router variable/import left over from the refactor, which does not affect runtime behavior.

apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts — minor cleanup of unused router/useRouter.

Important Files Changed

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts Swaps router.replace/push for window.history.replaceState on new-chat URL update to eliminate the navigation flash; leaves router/useRouter as unused dead code.

Sequence Diagram

sequenceDiagram
    participant User
    participant HomeChat as useChat (home)
    participant API as Mothership API
    participant BrowserHistory as window.history

    User->>HomeChat: sendMessage()
    HomeChat->>API: POST /api/mothership/chat
    API-->>HomeChat: SSE session event (chatId assigned)
    HomeChat->>BrowserHistory: replaceState(null, '', /workspace/{id}/task/{chatId})
    Note over HomeChat,BrowserHistory: URL silently updated — no Next.js route change, no flash
    API-->>HomeChat: SSE text/tool events
    HomeChat->>HomeChat: setMessages(), setResolvedChatId()
Loading

Comments Outside Diff (1)

  1. apps/sim/app/workspace/[workspaceId]/home/hooks/use-chat.ts, line 2174 (link)

    P2 Unused router dependency

    router is no longer called anywhere inside the processSSEStream callback — it was replaced with window.history.replaceState. Listing it as a dep is misleading and causes an unnecessary useCallback re-creation on the rare occasion useRouter returns a new reference. The const router = useRouter() declaration (line 712) and the useRouter named import (line 4) can also be removed.

Reviews (1): Last reviewed commit: "fix(ui): fix flash between home and new ..." | Re-trigger Greptile

@TheodoreSpeaks TheodoreSpeaks merged commit d6dc9f7 into staging Apr 14, 2026
14 checks passed
@TheodoreSpeaks TheodoreSpeaks deleted the fix/home-task-transition-flash branch April 14, 2026 01:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant